﻿using System;
using System.Linq;
using System.Web.Mvc;
using BabyShop.WebSite.Services;
using BabyShop.WebSite.ViewModels;

namespace BabyShop.WebSite.Controllers
{
    public class MenuController : Controller
    {
        private readonly ProductTypeService _productTypeService = new ProductTypeService();
        private readonly ProductService _productService = new ProductService();
        private readonly EnumServices _enumServices = new EnumServices();

        public ActionResult MainMenu()
        {
            var topLevelProductType = _productTypeService.GetTopLevelProductType();
            return PartialView(topLevelProductType);
        }

        public ActionResult LeftMenu()
        {
            var allProductType = _productTypeService.GetAllProductTypes(true);
            return PartialView(allProductType);
        }

        public ActionResult WebSiteLocation(Guid keyGuid, bool isProductType = false) {
            var product = isProductType ? null : _productService.GetProduct(keyGuid);
            var wsLViewModel = new WebSiteLocationViewModel {
                Product = product,
                ProductTypes =
                    _productTypeService.GetProductTypeTree(isProductType
                                                               ? keyGuid
                                                               : product.ProductTypeGuid)
            };

            return PartialView(wsLViewModel);
        }

        public ActionResult CategorySortList(Guid keyGuid) {
            var ptSortsViewModel = new ProductTypeSortsViewModel {
                CurrentProductType = _productTypeService.GetProductTypeByGuid(keyGuid)
            };
            return PartialView(ptSortsViewModel);
        }

        public ActionResult SubCategorySortList(Guid keyGuid)
        {
            var currPructType = _productTypeService.GetProductTypeByGuid(keyGuid);
            var ptSortsViewModel = new ProductTypeSortsViewModel
                                       {
                                           CurrentProductType = currPructType,
                                           TopProductType = currPructType.ParentProductType,
                                           SameProductTypes =
                                               _enumServices.GetSameProductTypes(currPructType.ParentGuid ?? Guid.Empty, currPructType.ProductTypeGuid)
                                               .ToList()
                                       };
            return PartialView(ptSortsViewModel);
        }
    }
}
